<?php
/*
Plugin Name:  Custom Logo
Plugin URI: http://www.wiso.cz/
Description: Replace WordPress default login/register page logo with custom one.
Version: 2.1
Author: Martin Wiso
Author URI: http://www.wiso.cz/
*/

if(!function_exists('wpcl_logo_css')) {	
	function wpcl_logo_css() {	
		// changed login dialog based on shuttle project we must replace original background
		$versioncode = '';
		if (get_bloginfo('version') >= 2.5) { 
			$versioncode = 'var obj = document.getElementById(\'login\');
			if (obj) {
				obj.firstChild.firstChild.style.background = \'url('.get_option('wpcl_custom_logo_path').') no-repeat center\';
			}';
		} else if (get_bloginfo('version') >= 2.1) { 
			$versioncode = "var obj = document.getElementById('login');
			if (obj) {
				obj.style.background = 'url(".get_settings('home')."/wp-content/plugins/custom-logo/images/2.1/login-bkg-tile.gif) no-repeat top center';
				var bgObj2 = document.getElementById('loginform');
				bgObj2.style.background = 'url(".get_settings('home')."/wp-content/plugins/custom-logo/images/2.1/login-bkg-bottom.gif) no-repeat bottom center';
			}
		";
		} else {			
			$versioncode = 'var obj = document.getElementsByTagName(\'H1\')[0];
			if (obj) {
				obj.style.background = \'url('.get_option('wpcl_custom_logo_path').') no-repeat center\';
				obj.style.margin = \'0\';
			}';
		}
    		
		// replace logo
		printf('<script type="text/javascript">
//<![CDATA[
window.onload = function() {
	try {	
		%s		
	}
	catch (e) {
		var message = (e.description) ? e.description : e;
		alert(message);
	}
};
</script>', $versioncode);
	}
}

/* Admin options */
if(!function_exists('wpcl_header')) {	
	function wpcl_header() {
		add_options_page('Custom Logo Options', 'Custom Logo', 'manage_options', 'custom-logo/custom-logo-options.php');
	}
}

add_action('login_form', 'wpcl_logo_css');
add_action('admin_head', 'wpcl_header');

// end of file
?>